<?php
    require_once dirname(dirname(__FILE__)) . '/shared/config/config.php';
    require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'check_admin_login.php';
    require_once DOCUMENT_ROOT . DIR_INCLUDE . 'html_generator.php';
    require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_affiliate.php';
    require_once DOCUMENT_ROOT . DIR_SHARED_LIBRARIES . 'lib_redirect.php';
    $title = 'Affiliate Priviledge';
    $success = NULL;
    $error = NULL;
    $btn_switch = filter_input(INPUT_POST, 'btn_switch');

    if (!empty($btn_switch)) {
        $aff_id_long           = strpos($btn_switch, '-');
        $switch_aff_id         = substr($btn_switch, 0, $aff_id_long);
        $switch_aff_priviledge = substr($btn_switch, $aff_id_long + 1);

        if (api_affiliate::switch_aff_priviledge($switch_aff_id, $switch_aff_priviledge)) {
            header($_SERVER['PHP_SELF']);
        }
    }
?>

<!DOCTYPE html>
<!--[if lt IE 7]>
<html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>
<html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>
<html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js">
<!--<![endif]-->

<html>
<head>
    <?php require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'head.php' ?>
</head>
<body>
<?php require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'header.php' ?>

<!-- Title -->
<div class="section section-black">
    <div class="container">
        <div class="row">
            <div class="col-md-12">
                <div class="calltoaction-wrapper">
                    <h3>Manage Choice</h3>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- End Title -->


<div class="ts-wrapper">

    <!-- Section Table -->
    <div class="section">
        <div class="container">
            <div class="row">
                <div class="col-md-12">
                    <div class="service-wrapper">
                        <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST">
                            <table class="table table-bordered">
                                <tr>
                                    <th class="text-center">ID</th>
                                    <th class="text-center">Affiliate ID</th>
                                    <th class="text-center">Username</th>
                                    <th class="text-center">Affiliate Commission</th>
                                    <th class="text-center">Current Privilege</th>
                                    <th class="text-center" colspan="2">Action</th>
                                </tr>
                                <?php
                                    $aff_priviledges = api_affiliate::get_aff_priviledges();
                                    foreach ($aff_priviledges as $aff_priviledge) :
                                        ?>
                                        <tr>
                                            <td class="text-center"><?php echo $aff_priviledge['id'] ?></td>
                                            <td class="text-center"><?php echo $aff_priviledge['aff_id'] ?></td>
                                            <td class="text-center"><?php echo $aff_priviledge['username'] ?></td>
                                            <td class="text-center"><?php echo $aff_priviledge['affiliate_commission'] ?></td>
                                            <td class="text-center" <?php echo(($aff_priviledge['aff_priviledge'] == 2) ? 'style="color: #E74C3C"' : ''); ?>>
                                                <?php echo(($aff_priviledge['aff_priviledge'] == 1) ? 'Standard' : 'Advance'); ?>
                                            </td>
                                            <td style="width: 240px" class="text-center">
                                                <button name="btn_switch" class="btn" value="<?php echo $aff_priviledge['aff_id'] ?>-<?php echo(($aff_priviledge['aff_priviledge'] == 1) ? '2' : '1'); ?>">
                                                    Switch
                                                    to <?php echo(($aff_priviledge['aff_priviledge'] == 2) ? '<b>Standard</b>' : '<b style="color: #ECF0F1; background: #2C3E50; padding: 10px;">Advanced</b>'); ?>
                                                    Affiliate
                                                </button>
                                            </td>
                                        </tr>
                                    <?php endforeach; ?>
                            </table>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- End Section Table -->
</div>

<?php require_once DOCUMENT_ROOT . DIR_ADMIN_INCLUDE . 'footer.php' ?>
</body>
</html>